package leetcode_top;

import java.util.*;
import java.util.stream.Collectors;

public class Ex384 {

    class Solution {

        Map<Integer, Integer> map;
        List<Integer> idx;
        int[] nums;
        int size;

        public Solution(int[] nums) {
            this.nums = nums;
            this.size = nums.length;
        }

        /** Resets the array to its original configuration and return it. */
        public int[] reset() {
            return nums;
        }

        /** Returns a random shuffling of the array. */
        public int[] shuffle() {
            List<Integer> res = new ArrayList<>();
            idx = Arrays.stream(nums).boxed().collect(Collectors.toList());
            int last, d, curSize;
            for (int i = 0; i < size; i++) {
                curSize = idx.size();
                d = (int) (Math.random() * curSize);
                res.add(idx.get(d));
                last = idx.remove(--curSize);
                if (curSize != 0) {
                    idx.set(d, last);
                }
            }
            return res.stream().mapToInt(Integer::valueOf).toArray();
        }
    }

    /**
     * Your Solution object will be instantiated and called as such: Solution obj =
     * new Solution(nums); int[] param_1 = obj.reset(); int[] param_2 =
     * obj.shuffle();
     */



}
